!############################# Change Log ##################################
! 5.0.0
!
!###########################################################################
!  Copyright (C)  1990, 1995, 1999, 2000, 2003 - All Rights Reserved
!  Regional Atmospheric Modeling System - RAMS
!###########################################################################

subroutine varf_update(iswap,ifileok,initflag)

use mem_leaf
use mem_varinit
use mem_basic
use mem_grid
use mem_scratch
use micphys

!--(DMK-CCATT)---------------------------------------------------------
!srf-chem
  use chem1_list 
  use mem_chem1, only: chem1_g,CHEM_ASSIM, CHEMISTRY
!srf-chem-end
!--(DMK-CCATT-END)-----------------------------------------------------

implicit none

integer :: ifileok,initflag,iswap

!---------------------------------------------------------------+
!    "Variable initialization"  initialization routines
!---------------------------------------------------------------+
logical there
integer :: iver_var,nc,iyearx,imonthx,idatex,ihourx  &
          ,nxpx,nypx,nzpx,imarker,iun

!--(DMK-CCATT)---------------------------------------------------------
!srf-chem
integer :: nspc,k
character(len=32) :: chemical_mechanism_test
!srf-chem-end
!--(DMK-CCATT-END)-----------------------------------------------------

real :: rlatx,wlon1x,deltaxx,deltayx,deltazx,dzratx,dzmaxx
character(len=7)   :: cgrid
character(len=128) :: flnm

!      Check and see what we are doing. If it is initial time, read
!        fields into regular arrays. If not, see if nudging will be done
!        on this grid if it is a nested grid.
if (ngrid > 1 .and. tnudcent+tnudtop < .001 .and. initflag == 0) return

! Put new fields into varinit future arrays. If iswap == 1, 
!     swap future into past first

if (iswap == 1) then
   varinit_g(ngrid)%varup(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))=  &
      varinit_g(ngrid)%varuf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))
   varinit_g(ngrid)%varvp(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))=  &
      varinit_g(ngrid)%varvf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))
   varinit_g(ngrid)%varpp(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))=  &
      varinit_g(ngrid)%varpf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))
   varinit_g(ngrid)%vartp(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))=  &
      varinit_g(ngrid)%vartf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))
   varinit_g(ngrid)%varrp(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))=  &
      varinit_g(ngrid)%varrf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))

!--(DMK-CCATT)---------------------------------------------------------    
   !srf-chem
   if(CHEM_ASSIM == on .and. CHEMISTRY >= 0) then 
       do nspc=1,nspecies
          if(spc_alloc(fdda,nspc) == on) &
           chem1_g(nspc,ngrid)%sc_pp(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid)) = &
           chem1_g(nspc,ngrid)%sc_pf(1:nnzp(ngrid),1:nnxp(ngrid),1:nnyp(ngrid))
       enddo
   endif
   !srf-chem-end
!--(DMK-CCATT-END)-----------------------------------------------------

endif

! Make data file name from tag file name
write(cgrid,'(a2,i1,a4)') '-g',ngrid,'.vfm'
nc=len_trim(fnames_varf(nvarffl))
flnm=fnames_varf(nvarffl)(1:nc-4)//trim(cgrid)

! Check for existence
inquire(file=trim(flnm),exist=there)

! Gotta have grid 1...
if (.not.there .and. ngrid == 1) then
   print*
   print*,'No grid 1 varfile found: ',trim(flnm)
   print*
   stop 'no grid 1 varfile'
endif

if(there) then
   ifileok=1
else
   ifileok=0
   return
endif


! Read the varfile fields into the "future" varinit arrays. These will be 
!   swapped to the past arrays when needed.
iun=22

call rams_f_open(iun,flnm,'FORMATTED','OLD','READ',0)

! Find varfile "version"
read(iun,*) imarker
rewind(iun)

if(imarker == 999999) then
   read(iun,*) imarker,iver_var
else
   iver_var=1
endif

read(iun,*) iyearx,imonthx,idatex,ihourx  &
     ,nxpx,nypx,nzpx,rlatx,wlon1x,deltaxx,deltayx,deltazx  &
     ,dzratx,dzmaxx

if(nxp.ne.nxpx.or.  &
   nyp.ne.nypx.or.  &
   nzp.ne.nzpx.or.  &
   abs(deltax-deltaxx).gt..001.or.  &
   abs(deltay-deltayx).gt..001.or.  &
   abs(deltaz-deltazx).gt..001.or.  &
   abs(dzrat-dzratx).gt..001.or.  & 
   abs(dzmax-dzmaxx).gt..001.or.  &
   abs(platn(ngrid)-rlatx).gt..001.or.  &
   abs(plonn(ngrid)-wlon1x).gt..001) then
   
   print*,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
   print*,'!!    GRID MISMATCH BETWEEN VARFILE AND NAMELIST !'
   print*,'!!          RUN IS STOPPED                       !'
   print*,'!!  File:',trim(flnm)
   print*,'!!  File, Namelist values for grid:',ngrid
   print*,'!!  nxp:',nxpx,nxp
   print*,'!!  nyp:',nypx,nyp
   print*,'!!  nzp:',nzpx,nzp
   print*,'!!  deltax:',deltaxx,deltax
   print*,'!!  deltay:',deltayx,deltay
   print*,'!!  deltaz:',deltazx,deltaz
   print*,'!!  dzrat:',dzratx,dzrat
   print*,'!!  dzmax:',dzmaxx,dzmax
   print*,'!!  polelat:',rlatx,platn(ngrid)
   print*,'!!  polelon:',wlon1x,plonn(ngrid)
   PRINT*,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
   stop 'bad-vfile'
endif

!--(DMK-CCATT)---------------------------------------------------------
!- test if the source data is for the chemical mechanism that will be used:
if(CHEM_ASSIM == on .and. CHEMISTRY >= 0) then 
   read(iun,*)  chemical_mechanism_test
   if(trim( chemical_mechanism_test ) /=  trim(chemical_mechanism)) then
       PRINT*,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
       print*,'chemical mechanism not the same as expected for 4DDA'
       print*,'expected=',trim(chemical_mechanism(1:len_trim(chemical_mechanism)))
       print*,'read    =',trim(chemical_mechanism_test(1:len_trim(chemical_mechanism_test)))
       stop 'wrong chem mechanism in varfiles - stop at chem_varf_update'
   endif
endif
!--(DMK-CCATT-END)-----------------------------------------------------

call vfirec(iun,varinit_g(ngrid)%varuf(1,1,1),nxyzp,'LIN')
call vfirec(iun,varinit_g(ngrid)%varvf(1,1,1),nxyzp,'LIN')
call vfirec(iun,varinit_g(ngrid)%varpf(1,1,1),nxyzp,'LIN')
call vfirec(iun,varinit_g(ngrid)%vartf(1,1,1),nxyzp,'LIN')
call vfirec(iun,varinit_g(ngrid)%varrf(1,1,1),nxyzp,'LIN')

varinit_g(ngrid)%varrf(1:nzp,1:nxp,1:nyp)=  &
           max(1.e-8,varinit_g(ngrid)%varrf(1:nzp,1:nxp,1:nyp) )

!--(DMK-CCATT)---------------------------------------------------------
!srf-chem
if(CHEM_ASSIM == on .and. CHEMISTRY >= 0) then 
    print*,'--------------------------------------------------------------------------'
    print*,' 4DDA using chem mechanism= ',trim(chemical_mechanism(1:len_trim(chemical_mechanism)))
   do nspc=1,nspecies
        if(spc_alloc(fdda,nspc) == on) then 
            call vfirec(iun,chem1_g(nspc,ngrid)%sc_pf(1,1,1),nxyzp,'LIN')
            !no futuro cheque o limite inferior (e-23)
            chem1_g(nspc,ngrid)%sc_pf(1:nzp,1:nxp,1:nyp)= init_ajust(nspc)*&
                     max(1.e-23,chem1_g(nspc,ngrid)%sc_pf(1:nzp,1:nxp,1:nyp))
	     
	     print*,' spc=',nspc,spc_name(nspc),maxval(chem1_g(nspc,ngrid)%sc_pf(1:nzp,1:nxp,1:nyp))
	     
	     
	     !if(spc_name(nspc) == 'O3' ) then
	     !  
	     !  print*,' => fixing O3 below 5 km'; call flush(6)
	     !  
	     !  do k=18, min(21,nzp)
	     !     chem1_g(nspc,ngrid)%sc_pf(k,1:nxp,1:nyp)=&
	!	  chem1_g(nspc,ngrid)%sc_pf(k,1:nxp,1:nyp)/init_ajust(nspc)*0.5
	!       enddo
	!       do k=22, nzp
	!          chem1_g(nspc,ngrid)%sc_pf(k,1:nxp,1:nyp)=&
	!	  chem1_g(nspc,ngrid)%sc_pf(k,1:nxp,1:nyp)/init_ajust(nspc)
	!       enddo
	!     endif
        endif
    enddo
    print*,'--------------------------------------------------------------------------'
endif
!srf-chem-end
!--(DMK-CCATT-END)------------------------------------------------------
         
if(initflag == 1 .and. iver_var == 2) then
   ! Extract snow depth from the varfile. Ignore other 2D fields for now.
   call vfirec(iun,scratch%vt2da(1),nxyp,'LIN')
   call vfirec(iun,scratch%vt2da(1),nxyp,'LIN')
   call vfirec(iun,scratch%vt2da(1),nxyp,'LIN')
   call vfirec(iun,leaf_g(ngrid)%snow_mass(1,1),nxyp,'LIN')
   call vfirec(iun,scratch%vt2da(1),nxyp,'LIN')
endif

close(iun)

! If running ADAP coord, do interpolation to Cartesian levels

if (if_adap == 1) then
   call varf_adap(nnzp(ngrid),nnxp(ngrid),nnyp(ngrid)  &
         ,varinit_g(ngrid)%varuf(1,1,1),varinit_g(ngrid)%varvf(1,1,1)  &
         ,varinit_g(ngrid)%varpf(1,1,1),varinit_g(ngrid)%vartf(1,1,1)  &
         ,varinit_g(ngrid)%varrf(1,1,1),grid_g(ngrid)%topta(1,1) )

!--(DMK-CCATT)---------------------------------------------------------
   !srf-chem
   if(CHEM_ASSIM == on .and. CHEMISTRY >= 0) then 
      do nspc=1,nspecies
         if(spc_alloc(fdda,nspc) == on)                                  & 
              call chem_varf_adap(nnzp(ngrid),nnxp(ngrid),nnyp(ngrid)     &
 	      ,chem1_g(nspc,ngrid)%sc_pf(1:nzp,1:nxp,1:nyp)          &
 	      ,grid_g(ngrid)%topta(1,1) )
      enddo
   endif
   !srf-chem-end
!--(DMK-CCATT-END)------------------------------------------------------
endif

! Find the reference state

if(initflag == 1 .and. ngrid == 1)  &
     call varref(nzp,nxp,nyp &
         ,varinit_g(ngrid)%vartf(1,1,1) ,varinit_g(ngrid)%varpf(1,1,1)  &
         ,basic_g(ngrid)%pi0(1,1,1),     basic_g(ngrid)%th0(1,1,1)  &
         ,varinit_g(ngrid)%varrf(1,1,1), basic_g(ngrid)%dn0(1,1,1)  &
         ,basic_g(ngrid)%dn0u(1,1,1),    basic_g(ngrid)%dn0v(1,1,1)  &
         ,varinit_g(ngrid)%varuf(1,1,1), varinit_g(ngrid)%varvf(1,1,1)  &
         ,grid_g(ngrid)%topt(1,1),       grid_g(ngrid)%topu(1,1)  &
         ,grid_g(ngrid)%topv(1,1),       grid_g(ngrid)%rtgt(1,1)  &
         ,grid_g(ngrid)%rtgu(1,1),       grid_g(ngrid)%rtgv(1,1)  &
         ,grid_g(ngrid)%topta(1,1), level)

varinit_g(ngrid)%varpf(1:nzp,1:nxp,1:nyp)=  &
           varinit_g(ngrid)%varpf(1:nzp,1:nxp,1:nyp)  &
           - basic_g(ngrid)%pi0(1:nzp,1:nxp,1:nyp)
           
! If this is an initialization, put data into regular arrays

if(initflag == 1 ) then
   call atob(nxyzp,varinit_g(ngrid)%varuf(1,1,1),basic_g(ngrid)%uc(1,1,1))
   call atob(nxyzp,varinit_g(ngrid)%varvf(1,1,1),basic_g(ngrid)%vc(1,1,1))
   call atob(nxyzp,varinit_g(ngrid)%varpf(1,1,1),basic_g(ngrid)%pc(1,1,1))
   call atob(nxyzp,varinit_g(ngrid)%vartf(1,1,1),basic_g(ngrid)%thp(1,1,1))
   call atob(nxyzp,varinit_g(ngrid)%varrf(1,1,1),basic_g(ngrid)%rtp(1,1,1))

!--(DMK-CCATT)---------------------------------------------------------
   !srf-chem
   if(CHEM_ASSIM == on .and. CHEMISTRY >= 0) then 
      do nspc=1,nspecies
         if(spc_alloc(fdda,nspc) == on) call atob(nxyzp        &
                           ,chem1_g(nspc,ngrid)%sc_pf(1,1,1)   &
                           ,chem1_g(nspc,ngrid)%sc_p (1,1,1)   )              
      enddo
   endif
   !srf-chem-end
!--(DMK-CCATT-END)------------------------------------------------------

endif


return
end

!     **************************************************************

subroutine varf_adap(n1,n2,n3,varu,varv,varp,vart,varr,topta)

use mem_scratch
use mem_grid
use rconstants

implicit none

integer :: n1,n2,n3
real, dimension(n1,n2,n3) :: varu,varv,varp,vart,varr
real, dimension(n2,n3) :: topta

integer :: i,j,k

! Interpolate from sigma-z varfile vertical coords to ADAP grid


do j=1,n3
   do i=1,n2
   
      do k=1,n1
         vctr10(k)=topta(i,j) + (1.-topta(i,j)/ztop)*ztn(k,ngrid)
      enddo
      vctr1(1:n1)=varu(1:n1,i,j)
      vctr2(1:n1)=varv(1:n1,i,j)
      vctr3(1:n1)=vart(1:n1,i,j)
      vctr4(1:n1)=varr(1:n1,i,j)
      call htint2(n1,vctr1(1),vctr10,n1,vctr11(1),ztn(1,ngrid))
      call htint2(n1,vctr2(1),vctr10,n1,vctr12(1),ztn(1,ngrid))
      call htint2(n1,vctr3(1),vctr10,n1,vctr13(1),ztn(1,ngrid))
      call htint2(n1,vctr4(1),vctr10,n1,vctr14(1),ztn(1,ngrid))

      ! Do hydrostatic balance
      do k=1,n1
         vctr15(k) = vctr13(k)* (1.+.61*vctr14(k))
      enddo

      vctr16(n1)= varp(n1,i,j) + g * (ztn(n1,ngrid) - vctr10(n1) )  &
               / vctr15(n1)
      do k = n1-1,1,-1
         vctr16(k) = vctr16(k+1) + g * (ztn(k+1,ngrid)-ztn(k,ngrid))  &
               /((vctr15(k)+vctr15(k+1))*.5)
      enddo
      
     varu(1:n1,i,j)= vctr11(1:n1)
     varv(1:n1,i,j)= vctr12(1:n1)
     vart(1:n1,i,j)= vctr13(1:n1)
     varr(1:n1,i,j)= vctr14(1:n1)
     varp(1:n1,i,j)= vctr16(1:n1)
      
   enddo      
enddo

return
end

!     **************************************************************

subroutine varref(n1,n2,n3,thp,pc,pi0,th0,rtp,dn0,dn0u,dn0v,uc  &
                 ,vc,topt,topu,topv,rtgt,rtgu,rtgv,topta,level)

use mem_grid
use ref_sounding
use mem_scratch
use rconstants
use catt_start, only: CATT           ! intent(in)
                 
implicit none
integer :: n1,n2,n3,level          
real :: thp(n1,n2,n3),pc(n1,n2,n3),pi0(n1,n2,n3)  &
         ,rtp(n1,n2,n3),dn0(n1,n2,n3)  &
         ,dn0u(n1,n2,n3),dn0v(n1,n2,n3)  &
         ,uc(n1,n2,n3),vc(n1,n2,n3),topt(n2,n3),topu(n2,n3)  &
         ,topv(n2,n3),rtgt(n2,n3),rtgu(n2,n3),rtgv(n2,n3)  &
         ,th0(n1,n2,n3),topta(n2,n3)

integer :: i,j,k

!-srf - for reference state = mean of 2d fields
real,allocatable, dimension(:) :: thp_m2d,uc_m2d,vc_m2d,rtp_m2d,pc_m2d
integer ncount 
integer, parameter :: ref_mean=0
!                Reference sounding is point with lowest topography
!srf- including Tremback's recommendation for iref,jref
!orig-version
topref=1.e10
do j=1,nyp
   do i=1,nxp
      if(topta(i,j).lt.topref) then
         iref=i
         jref=j
         topref=topta(i,j)
      endif
   enddo
enddo
if(CATT==1) then
!- version 2 : ref == center of the domain
iref=int(nxp/2)
jref=int(nyp/2)
topref=topta(iref,jref)
print*,'Reference sounding is at=',iref,jref,topref
endif


!srf - version 3 - mean over horizontal model domain
if(ref_mean == 1 ) then 
  
  allocate(thp_m2d(n1),uc_m2d(n1),vc_m2d(n1),rtp_m2d(n1),pc_m2d(n1))
  thp_m2d=0.;uc_m2d=0.;vc_m2d=0.;rtp_m2d=0.; pc_m2d=0.
  
  if(level == 0) stop 'varf updated ' 
  do k = 1,nzp
    ncount = 0
    do j=1,n3; do i=1,n2
      thp_m2d (k)= thp_m2d (k) + thp(k,i,j)
      pc_m2d  (k)= pc_m2d (k)  + pc(k,i,j)
      uc_m2d  (k)= uc_m2d  (k) +  uc(k,i,j)
      vc_m2d  (k)= vc_m2d  (k) +  vc(k,i,j)
      rtp_m2d (k)= rtp_m2d (k) + rtp(k,i,j)
      ncount = ncount +1
    enddo;enddo
    thp_m2d (k)= thp_m2d (k)/float(ncount)
     pc_m2d (k)= pc_m2d (k)/float(ncount)
    uc_m2d  (k)= uc_m2d  (k)/float(ncount)
    vc_m2d  (k)= vc_m2d  (k)/float(ncount)
    rtp_m2d (k)= rtp_m2d (k)/float(ncount)
    !print*,'ref=',k,thp_m2d (k), pc_m2d (k),uc_m2d  (k),vc_m2d  (k),rtp_m2d (k)
  enddo
  topref=0.
  ncount=0    
  do j=1,n3; do i=1,n2
    topref=topref+topta(i,j)
    ncount = ncount +1
  enddo;enddo
  topref=topref/float(ncount)

endif  
!------

!  Set up 1-D reference state

if (if_adap == 0) then

!srf : mean over horizontal model domain
 if(ref_mean == 1 ) then 
       
       do k=1,nzp
    	  vctr2(k)=ztn(k,ngrid)*(1.-topref/ztop)+topref
       enddo
       call htint2(nzp, thp_m2d,vctr2,nzp,vctr1,zt)
       call htint2(nzp, uc_m2d ,vctr2,nzp,u01dn(1,ngrid),zt)
       call htint2(nzp, vc_m2d ,vctr2,nzp,v01dn(1,ngrid),zt)
       if (level >= 1) then
    	  call htint2(nzp,rtp_m2d,vctr2,nzp,rt01dn(1,ngrid),zt)
       else
    	  rt01dn(1:nzp,ngrid) = 0.
       endif

 else
       do k=1,nzp
    	  vctr2(k)=ztn(k,ngrid)*(1.-topref/ztop)+topref
       enddo
       call htint2(nzp,thp(1,iref,jref),vctr2,nzp,vctr1,zt)
       call htint2(nzp,uc(1,iref,jref),vctr2,nzp,u01dn(1,ngrid),zt)
       call htint2(nzp,vc(1,iref,jref),vctr2,nzp,v01dn(1,ngrid),zt)
       if (level >= 1) then
    	  call htint2(nzp,rtp(1,iref,jref),vctr2,nzp,rt01dn(1,ngrid),zt)
       else
    	  rt01dn(1:nzp,ngrid) = 0.
       endif
 endif


else
   vctr2(1:nzp)  =ztn(1:nzp,ngrid)
   vctr1(1:nzp)  =thp(1:nzp,iref,jref)
   u01dn(1:nzp,ngrid)=uc(1:nzp,iref,jref)
   v01dn(1:nzp,ngrid)=vc(1:nzp,iref,jref)
   rt01dn(1:nzp,ngrid) = 0.
   if (level >= 1) rt01dn(1:nzp,ngrid)=rtp(1:nzp,iref,jref)
endif


do k = 1,nzp
   th01dn(k,ngrid) = vctr1(k) * (1. + .61 * rt01dn(k,ngrid))
enddo
u01dn(1,ngrid) = u01dn(2,ngrid)
v01dn(1,ngrid) = v01dn(2,ngrid)
rt01dn(1,ngrid) = rt01dn(2,ngrid)
th01dn(1,ngrid) = th01dn(2,ngrid)


!srf : mean over horizontal model domain
if(ref_mean == 1 ) then 

   pi01dn(1,ngrid) = pc_m2d(1) + g * (vctr2(1) - zt(1))  &
      / (.5 * (th01dn(1,ngrid)  &
      + thp_m2d(1) * (1. + .61 * rtp_m2d(1))))

else

   pi01dn(1,ngrid) = pc(1,iref,jref) + g * (vctr2(1) - zt(1))  &
      / (.5 * (th01dn(1,ngrid)  &
      + thp(1,iref,jref) * (1. + .61 * rtp(1,iref,jref))))

endif

do k = 2,nzp
   pi01dn(k,ngrid) = pi01dn(k-1,ngrid) - g / (dzm(k-1) * .5  &
   * (th01dn(k,ngrid) + th01dn(k-1,ngrid)))
enddo


do k = 1,nzp
  vctr4(k) = (pi01dn(k,ngrid) / cp) ** cpor * p00
  dn01dn(k,ngrid) = cp * vctr4(k)  &
     / (rgas * th01dn(k,ngrid) * pi01dn(k,ngrid))
enddo

!        Compute 3-D reference state from 1-D reference state

call refs3d(nzp,nxp,nyp,pi0,dn0,dn0u,dn0v,th0,topt,rtgt)


!srf
if(ref_mean == 1 ) deallocate(thp_m2d,uc_m2d,vc_m2d,rtp_m2d,pc_m2d)


return

end


!--(DMK-CCATT)---------------------------------------------------------
!     **************************************************************
!srf-chem
subroutine chem_varf_adap(n1,n2,n3,varr,topta)

use mem_scratch
use mem_grid
use rconstants

implicit none

integer :: n1,n2,n3
real, dimension(n1,n2,n3) :: varr
real, dimension(n2,n3) :: topta

integer :: i,j,k

! Interpolate from sigma-z varfile vertical coords to ADAP grid


do j=1,n3
   do i=1,n2
   
      do k=1,n1
         vctr10(k)=topta(i,j) + (1.-topta(i,j)/ztop)*ztn(k,ngrid)
      enddo
      vctr4(1:n1)=varr(1:n1,i,j)
      call htint2(n1,vctr4(1),vctr10,n1,vctr14(1),ztn(1,ngrid))

      varr(1:n1,i,j)= vctr14(1:n1)
      
   enddo      
enddo

return
end
!srf-chem-end
!--(DMK-CCATT-END)------------------------------------------------------
